﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Odin.Base.IO;

namespace Odin.Base {
    public partial class Window : Form {
        public int _Width, _Height;

        private bool _Resizable = false, _FullScreen = false;
        private String _Title, _Text;

        public Window(int Width = 500, int Height = 500, bool FullScreen = false, String Title = "Window", String Text = "A Basic Window") {
            _Width = Width;
            _Height = Height;
            _FullScreen = FullScreen;
            _Title = Title;
            _Text = Text;
            Initialize();
        }

        private void Initialize() {
            // Call the designers intialize
            InitializeComponent();

            // Do the rest of my own initializing
            this.Name = "Window";
            this.Text = _Title + " - " + _Text;
            this.ClientSize = new Size(_Width, _Height);
            this.CenterToScreen();

            if (!_Resizable) {
                this.MinimumSize = ClientSize;
                this.MaximumSize = ClientSize;
            }

            // LOG: Main Window Created
        }

        public void ToggleResizable() {
            if (InvokeRequired) {
                this.Invoke(new MethodInvoker(delegate {
                    if (_Resizable) {
                        MinimumSize = new Size(Width, Height);
                        MaximumSize = new Size(Width, Height);
                        _Resizable = false;
                    } else {
                        MinimumSize = new Size(_Width / 10, _Height / 10);
                        MaximumSize = new Size(_Width, _Height);
                        _Resizable = true;
                    }
                }));
                return;
            } else {
                if (_Resizable) {
                    MinimumSize = new Size(Width, Height);
                    MaximumSize = new Size(Width, Height);
                    _Resizable = false;
                } else {
                    MinimumSize = new Size(_Width / 10, _Height / 10);
                    MaximumSize = new Size(_Width, _Height);
                    _Resizable = true;
                }
            }
        }

        public void Draw() {
            // Execute sub-draws
        }

        #region Handlers

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e) {
            OdinEngine.Stop();
            base.OnClosing(e);
        }

        #endregion
    }
}
